package grpc

import (
	"fmt"
	"google.golang.org/grpc"
	"google.golang.org/grpc/health"
	"google.golang.org/grpc/health/grpc_health_v1"
	"log"
	"net"
)

func RegisterGrpc(call func(server *grpc.Server)) {
	lis, err := net.Listen("tcp", fmt.Sprintf("%s", "127.0.0.1:8899"))
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}
	s := grpc.NewServer()

	// todo 健康监测
	call(s)

	grpc_health_v1.RegisterHealthServer(s, health.NewServer())

	log.Printf("server listening at %v", lis.Addr())
	if err := s.Serve(lis); err != nil {
		log.Fatalf("failed to serve: %v", err)
	}
}
